package com.love.marriage.userLoginInfo.service.impl;

import com.love.marriage.userLoginInfo.entity.UserLoginInfo;
import com.love.marriage.userLoginInfo.vo.UserLoginInfoVo;
import com.love.marriage.userLoginInfo.mapper.UserLoginInfoMapper;
import com.love.marriage.userLoginInfo.service.UserLoginInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import com.love.marriage.utils.StringUtils;

/**
 * <p>
 * description:  用户登录历史表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-10-12 11:25:06
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class UserLoginInfoServiceImp extends ServiceImpl<UserLoginInfoMapper, UserLoginInfo> implements UserLoginInfoService {

    private final UserLoginInfoMapper userLoginInfoMapper;

    @Override
    public Page<UserLoginInfoVo> getPage(Long pageNum, Long pageSize, UserLoginInfoVo userLoginInfoVo) {
        Page<UserLoginInfoVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return userLoginInfoMapper.getPage(page, userLoginInfoVo);
    }

    @Override
    public UserLoginInfoVo queryUserLoginInfo(Long id) {
        return userLoginInfoMapper.queryUserLoginInfo(id);
    }

    @Override
    public Boolean addUserLoginInfo(UserLoginInfoVo userLoginInfoVo) {
        UserLoginInfo userLoginInfo = new UserLoginInfo();
        BeanUtils.copyProperties(userLoginInfoVo, userLoginInfo);
        userLoginInfoMapper.insert(userLoginInfo);
        return true;
    }

    @Override
    public Boolean updateUserLoginInfo(UserLoginInfoVo userLoginInfoVo) {
        UserLoginInfo userLoginInfo = new UserLoginInfo();
        BeanUtils.copyProperties(userLoginInfoVo, userLoginInfo);
        userLoginInfoMapper.updateById(userLoginInfo);
        return true;
    }

    @Override
    public Boolean deleteUserLoginInfo(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        userLoginInfoMapper.deleteBatchIds(idArr);
        return true;
    }
}
